package cn.alpha.intell.rbtlib.broadcast;

import android.content.Context;
import android.content.Intent;

/**
 *
 *封装广播消息
 * Created by zhangxiliang on 2016/9/23.
 */
public class AlphaMessageManager {

    private static AlphaMessageManager instance;

    public static  final String CONTENT="content";

    public static final String ALPHA_ACTION_NAME=".ACTION.RECEIVE_ALPHA_NOTIFICATION";

    private static Context mContext;
    private AlphaMessageManager (){}


    public static void init(Context context){
          mContext=context.getApplicationContext();
    }

    /**
     * 发送透传消息到Mob
     * @param message
     * @param osApp
     */
    public static void sendP2PMessage(AlphaMessage message,OSApp osApp){
        Intent  intent=new Intent();
        intent.setPackage(osApp.getValue());
        intent.setAction(osApp.getValue()+ALPHA_ACTION_NAME);
        mContext.sendBroadcast(intent);
    }

    /**
     * 发送普通广播到其他APP，不包含数据
     * @param alphaMsgType
     * @param osApp
     */
    public  static void sendBrocast(AlphaMsgType alphaMsgType,OSApp osApp){
        Intent  intent=new Intent();
        intent.setPackage(osApp.getValue());
        intent.setAction(osApp.getValue()+ALPHA_ACTION_NAME);
        intent.putExtra(CONTENT,alphaMsgType.getValue());
        mContext.sendBroadcast(intent);
    }

    /***
     * 只能发送给当前应用的广播
     * @param action
     */
    public static void sendBrocast(String action){
        Intent  intent=new Intent();
        intent.setPackage(mContext.getPackageName());
        intent.setAction(action);
        mContext.sendBroadcast(intent);
    }

    /***
     * 发送普通广播到其他APP，包含数据
     * @param message
     * @param osApp
     */
    public static void sendBrocast(AlphaMessage message,OSApp osApp){
        Intent  intent=new Intent();
        intent.setPackage(osApp.getValue());
        intent.setAction(osApp.getValue()+ALPHA_ACTION_NAME);
        intent.putExtra(CONTENT,message);
        mContext.sendBroadcast(intent);
    }


}
